package com.edu.exam.entity.auth;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.Builder.Default;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 系统用户实体类
 * 所属模块：F-01 用户管理模块 (认证与权限管理)
 * 对应数据库表：user
 * 用于管理系统管理员、教师等系统用户
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "user")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SystemUser extends BaseUser {

    @NotBlank(message = "密码不能为空")
    @Size(min = 6, max = 100, message = "密码长度必须在6-100个字符之间")
    @Column(name = "password", nullable = false, length = 100)
    private String password;

    @Email(message = "邮箱格式不正确")
    @Size(max = 100, message = "邮箱长度不能超过100个字符")
    @Column(name = "email", unique = true, length = 100)
    private String email;

    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    @Column(name = "phone", unique = true, length = 20)
    private String phone;

    @Column(name = "department_id")
    private Long departmentId;

    @Size(max = 100, message = "职位长度不能超过100个字符")
    @Column(name = "position", length = 100)
    private String position;

    @Column(name = "employee_number", unique = true, length = 50)
    private String employeeNumber;

    @Default
    @Column(name = "failed_login_attempts")
    private Integer failedLoginAttempts = 0;

    @Column(name = "account_locked_until")
    private LocalDateTime accountLockedUntil;

    @Column(name = "password_changed_at")
    private LocalDateTime passwordChangedAt;

    /**
     * 获取用户类型标识
     * @return 系统用户类型标识
     */
    @Override
    public String getUserType() {
        return "SYSTEM";
    }
}